package template_method

import "fmt"

type OrderStep interface {
	Create()
	Pay()
	NeedDeliver() bool
	Deliver()
}

type Order struct {
	step OrderStep
}

func (o *Order) Process() {
	o.step.Create()
	o.step.Pay()
	if o.step.NeedDeliver() {
		o.step.Deliver()
	}
}

func (o *Order) SetStep(step OrderStep) {
	o.step = step
}

// PhysicalOrder 实物商品订单
type PhysicalOrder struct {
	Order
}

func (p *PhysicalOrder) Create()  {
	fmt.Println("创建实物商品订单")
}

func (p *PhysicalOrder) Pay()  {
	fmt.Println("支付实物商品订单")
}

func (p *PhysicalOrder) NeedDeliver() bool {
	return true
}

func (p *PhysicalOrder) Deliver()  {
	fmt.Println("发货实物商品订单")
}

// VirtualOrder 虚拟商品订单
type VirtualOrder struct {
	Order
}

func (v *VirtualOrder) Create()  {
	fmt.Println("创建虚拟商品订单")
}

 func (v *VirtualOrder) Pay()  {
	fmt.Println("支付虚拟商品订单")
}

func (v *VirtualOrder) NeedDeliver() bool {
	return false
}

func (v *VirtualOrder) Deliver()  {
}